package rest

import (
	"context"
	"dawn/conf"
	"dawn/model"

	"github.com/smallnest/rpcx/client"
)

// LoginRPCCall 登录 RPC 调用
func LoginRPCCall(n string, p string) *model.LoginReply {
	d := client.NewZookeeperDiscovery(conf.Conf.RPCBasePath, "UserRPC", []string{conf.Conf.ZkAddr}, nil)
	xclient := client.NewXClient("UserRPC", client.Failtry, client.RandomSelect, d, client.DefaultOption)
	defer xclient.Close()

	args := &model.LoginArgs{
		Username: n,
		Password: p,
	}
	reply := &model.LoginReply{}

	err := xclient.Call(context.Background(), "LoginRPCServ", args, reply)
	if err != nil {
		return &model.LoginReply{Code: "9999", Msg: err.Error(), Data: ""}
	}
	return reply
}
